package com.demo.coupon;


import com.demo.AppletConstant;
import com.demo.util.Utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;


/**
 * 赠送优惠券
 *
 */
public class CouponDownload {
	public static SimpleDateFormat SDF_HMS = new SimpleDateFormat("yyyyMMdd");

	public static void main(String[] args)  throws Exception{

		//调用接口地址
		String url = "https://open.95516.com/open/access/1.0/coupon.download";
		
		//拼装参数Map
		Map<String, String> params = new HashMap<String, String>(0);
		params.put("appId", AppletConstant.APP_ID);
		//交易流水号,不重复，最大64位
		params.put("transSeqId", "");
		params.put("transTs", SDF_HMS.format(new Date()));
		//订单金额
		params.put("couponId", "");
		params.put("mobile", "");
		params.put("cardNo", "");
		params.put("openId", AppletConstant.openId);

		//赠送维度，2位，可选：01-手机号 02-卡号 03-用户（三选一）
		params.put("acctEntityTp", "");
		params.put("couponNum", "");

		//随机字符串，用于验签
		String nonceStr = Utils.createNonceStr();
		params.put("nonceStr", nonceStr);
		//生成时间戳
		String timestamp = String.valueOf(System.currentTimeMillis()/1000);
		params.put("timestamp", timestamp);
		//签名
		String signature = Utils.sign(params, AppletConstant.SIGN_KEY_PACKET);
		params.put("signature", signature);

		//针对敏感字段加密
		Utils.encryptedParamMap(AppletConstant.SYMMETRIC_KEY, params, "mobile","cardNo");

		//发送请求
		String resultStr = Utils.sendPostGson(url, params);
		
		System.out.println("-------赠送优惠券:"+resultStr+"---------");
	}
	
}
